//
//  RecruitmentListCell.m
//  cityStar
//
//  Created by joyban on 15-1-21.
//  Copyright (c) 2015年 tiny. All rights reserved.
//

#import "RecruitmentListCell.h"
#import "UIColor+FlatUI.h"

@implementation RecruitmentListCell

+(CGFloat)heightOfTableCell
{
    return 88;
}

- (void)awakeFromNib {
    // Initialization code
}

-(void)setdataRecruit:(RecruitmetArrayModel *)model
{
    self.titleLabel.text = model.title;
    NSInteger typestring = [[NSString stringWithFormat:@"%@",model.category] integerValue];
    switch (typestring) {
        case 1:
            self.typelaebl.text = @"全职";
            break;
        case 2:
            self.typelaebl.text = @"兼职";
            break;
        case 3:
            self.typelaebl.text = @"实习";
            break;
        default:
            break;
    }
    NSInteger moneyStr = [[NSString stringWithFormat:@"%@",model.salary] integerValue];
    switch (moneyStr) {
        case 1:
            self.namelabel.text = @"3000以下";
            break;
        case 2:
            self.namelabel.text = @"3000-5000元/月";
            break;
        case 3:
            self.namelabel.text = @"5000-8000元/月";
            break;
        case 4:
            self.namelabel.text = @"8000-15000元/月";
            break;
        case 5:
            self.namelabel.text = @"15000-20000元/月";
            break;
        case 6:
            self.namelabel.text = @"20000+元/月";
            break;
        case 7:
            self.namelabel.text = @"面议";
            break;
        default:
            break;
    }
    self.addresslaebl.text = model.district_name;
    self.contentlabel.text = [NSString stringWithFormat:@"%@",model.line];
    
//    NSInteger leinStr = [[NSString stringWithFormat:@"%@",model.degree] integerValue];
//    switch (leinStr) {
//        case 0:
//            self.contentlabel.text = @"学历不限";
//            break;
//        case 1:
//            self.contentlabel.text = @"学历初中";
//            break;
//        case 2:
//            self.contentlabel.text = @"学历高中";
//            break;
//        case 3:
//            self.contentlabel.text = @"学历专专";
//            break;
//        case 4:
//            self.contentlabel.text = @"学历大专";
//            break;
//        case 5:
//            self.contentlabel.text = @"学历本科";
//            break;
//        case 6:
//            self.contentlabel.text = @"学历硕士";
//            break;
//        case 7:
//            self.contentlabel.text = @"学历博士";
//            break;
//        case 8:
//            self.contentlabel.text = @"学历留学";
//            break;
//        default:
//            break;
//    }
    
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[[NSString stringWithFormat:@"%@",model.modify_time] intValue]];
    
    NSLog(@"date1:%@",confromTimesp);
    self.timeLaebl.text = [self dateStringFromNow:confromTimesp];
    
    NSString *status = [NSString stringWithFormat:@"%@",model.status];
    if([status isEqualToString:@"0"])
    {
        self.titleLabel.textColor = [UIColor colorFromHexCode:@"949494"];
        NSString *name = [NSString stringWithFormat:@"%@%@",@"[已作废]",model.title];
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:name];
        [attri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 5)];
        [self.titleLabel setAttributedText:attri];
        self.typelaebl.backgroundColor = [UIColor colorFromHexCode:@"949494"];
        self.namelabel.textColor = [UIColor colorFromHexCode:@"949494"];
        self.contentlabel.backgroundColor = [UIColor colorFromHexCode:@"949494"];
    }
}

-(NSString*)dateStringFromNow:(NSDate*)date{
    NSTimeInterval time = -[date timeIntervalSinceNow];
    if (time<0) {
        return @"";
    }else {
        if (time<3600*24) {
            if (time>=0.0 && time <60.0) {
                return @"刚刚";
            }else if (time>=60.0 && time <60.0*60.0) {
                return [NSString stringWithFormat:@"%d分钟前",(int)time/60];
            }else if (time>=3600.0 && time <3600.0*24) {
                return [NSString stringWithFormat:@"%d小时前",(int)time/3600];;
            }
        }else {
            NSCalendar* calendar = [NSCalendar currentCalendar];
            NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit|NSWeekCalendarUnit fromDate:date toDate:[NSDate date] options:0];
            if ([components year]>0) {
                int month = [components year]*12+[components month];
                return [NSString stringWithFormat:@"%d月前",month];
            }else if([components month]>0){
                int month = [components month];
                return [NSString stringWithFormat:@"%d月前",month];
            }else if([components week]>0){
                return [NSString stringWithFormat:@"%d周前",[components week]];
            }else if([components day]>0){
                return [NSString stringWithFormat:@"%d天前", [components day]];
            }
        }
    }
    return @"";
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
